#include <iostream>
#include <ctime>
#include <string.h>
using namespace std;





int main(){
	int ans=0;
	string a,b;
	cin>>a>>b;
	a = "A"+a;
	b = "A"+b;
//	cout<<a<<" "<<b<<endl;
	int al=a.length(),bl=b.length();
	int dp[al+1][bl+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=al;i++){
		for(int j=1;j<=bl;j++){
			if(a[i-1] == b[j-1])
				dp[i][j] = dp[i-1][j-1]+1;
			else
				dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
		}
	}
//	cout<<1<<endl;
	int x=al,y=bl,xl=0,yl=0;
	while(dp[x][y] != 0){
		if(dp[x-1][y] == dp[x][y]  ||  y == 0){
			x--;
			xl++;
		}
		else if(dp[x][y-1] == dp[x][y]  ||  x == 0){
			y--;
			yl++;
		}
		else{
			ans += max(xl,yl);
			xl = 0;
			yl = 0;
			x--;
			y--;
		}
	}
	cout<<ans;
	return 0;
}
